<?php
/**
 * Created by PhpStorm.
 * User: wangyh
 * Date: 15-12-24
 * Time: 下午3:20
 */
class SQLitePDO extends PDO {
    function __construct($filename) {
        //$filename = realpath($filename);
        parent::__construct('sqlite:' . $filename);
        $key = ftok($filename, 'a');

        //$this->sem = sem_get($key);
    }

    function beginTransaction() {
        //sem_acquire($this->sem);
        return parent::beginTransaction();
    }

    function commit() {
        $success = parent::commit();
        //sem_release($this->sem);
        return $success;
    }

    function rollBack() {
        $success = parent::rollBack();
        //sem_release($this->sem);
        return $success;
    }

    function query($sql){
        $success = parent::query($sql);
        //sem_release($this->sem);
        return $success;
    }

    function create($sql){
        $success = parent::create($sql);
        //sem_release($this->sem);
        return $success;
    }

    function fetchOne($sql){
        $records = parent::query($sql);
        if(empty($records)){
            return false;
        }
        foreach($records as $record){
            return $record;
        }
    }

    function fetchAll($sql){
        $results = parent::query($sql);
        //$results->setFetchMode(PDO::FETCH_NUM);
        $records = array();
        foreach($results as $record){
            $records[] = $record;
        }
        return $records;
    }

}